home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4955 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: altair.dur.ac.uk!d51qvn
  2. From: P D Johnson <P.D.Johnson@durham.ac.uk>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: New printf - like function, is it possible?
  5. Followup-To: comp.lang.c,comp.lang.c++
  6. Date: 1 Feb 1996 20:30:39 GMT
  7. Organization: University of Durham, Durham, UK.
  8. Message-ID: <4er7tf$f0u@mercury.dur.ac.uk>
  9. References: <4eqb3a$2r5@pan.otol.fi>
  10. NNTP-Posting-Host: altair.dur.ac.uk
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Timo Sakari (tkes@rhea.otol.fi) wrote: 
  14.  
  15. : Hi!
  16.  
  17. : Do you C-gurus have any solutions to this problem?
  18.  
  19. : I am programming under MS Windows 3.1 (this is NOT an OS spesific 
  20. : question!)and I would like to create
  21. : some kind of modified print function, which syntax should be something
  22. : like normal printf; because in Windows printf can't be used, everything
  23. : printed to screen has to come through message boxes etc, and before 
  24. : displaying anything, the string to displayed has to be formed. I have 
  25. : created my own printing function, which wants parameters string and winID
  26. : to know where to put that string, something like this: 
  27.  
  28. : sprintf(printStr, "some sfuff, variables %d, %f, etc", var1, var2);
  29. : PrintToWin(DEBUG_WIN_1, printStr);
  30.  
  31. : However, I want to write a "better" printing function, where string to be
  32. : formed doesn't need to be formatted first, it can be displayed and formed
  33. : at the same time in the same syntax like printf, something like these:
  34.  
  35. : PrintToWin(DEBUG_WIN_1, "some stuff etc, %d, %f, %s, var1, var2, str1);
  36. : PrintToWin(OTHER_WIN, "anything that printf accepts");
  37.  
  38. : So I want to print almost anything with this function without having
  39. : to write many functions to different argument types/number of arguments.
  40. : This should be possible in C++ (is it?), but is it possible in C ?
  41. : Can this be achieved by using void pointers and macros etc., or should
  42. : I give up and don't waste my time on this?
  43.  
  44. : Any help would be greatly appreciated. Thanks.
  45.  
  46. You will be glad to know there is a library specialy for this :-)
  47.  
  48. Have you tried looking at the supplied args function's that come with C 
  49. that allow you to write functions that do not know how many or what type 
  50. of parameters are being passed. printf() is an example of this if you 
  51. look in <stdio.h> you will see it has been prototyped something like
  52.  printf(...) were the three dots mean any parameters can be passed. The 
  53. library <args.h>? then provides you with functions to get at the values 
  54. of the passed parameters. 
  55.  
  56. You will need to follow printf()'s example of passing a string as you have 
  57. no way of knowing what type the passed parameters are. Hence all the 
  58. %s, %d in the string.
  59.  
  60. Have fun, you will not need the function overloading abilities of C++
  61.  
  62. Paul
  63.